package edu.biwu.service.impl;

import edu.biwu.service.UserService;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

//ConfigurableBeanFactory.SCOPE_SINGLETON 单实例 每次创建对象都是同一个对象
//ConfigurableBeanFactory.SCOPE_PROTOTYPE 多实例 每次创建对象都是不同的对象
/*@Scope:指定Bean的作用域
        @PostConsturct: 标注在初始化方法,当构造方法执行后,执行初始化方法,相当于init-method属性
        @PreDestroy:标注在销毁方法上,如果Bean是单例的话,当Spring容器关闭的时候,会调用Bean的销毁方法 相当于destroy-method属性
        <bean class="com.myspring.service.BeanLifecycleService" id="beanLifecycleService"
        init-method="init"
        destroy-method="destroy"/>*/
@Service
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class UserServiceImpl05 implements UserService {

    public UserServiceImpl05() {
        System.out.println(this+"构造函数");
    }

    @PostConstruct
    public void init() {
        System.out.println(this+"被初始化");
    }

    @PreDestroy
    public void destroy() {
        System.out.println(this+"被销毁");
    }
}
